home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TDE.ARJ / TDECLUST.CPP < prev    next >
C/C++ Source or Header  |  1992-07-14  |  8KB  |  250 lines

  1. /***************************************************************************
  2.  
  3.  FILENAME - TDECLUST.CPP: classes TDEButton, TDERadioButtons, TDECheckBoxes
  4.  -----------------------
  5.  
  6.  Class TDataEntry v1.0 - 07/14/92
  7.  --------------------------------
  8.  
  9.  ----------------------------------------------------------------------------
  10.  Author: Jeff Penrose * JDP Custom Software * (818) 344-7303 * CIS 71043,3727
  11.  ----------------------------------------------------------------------------
  12.  
  13.  A data entry class for Borland's Turbo Vision, derived from TInputLine.
  14.  
  15.  Copyright Notice
  16.  ================
  17.   As this material is ultimately derived from Borland source files, any of
  18.  their copyrights which MAY apply DO apply.
  19.   From the author's standpoint, you may use this material freely and,
  20.  hopefully, post any comments/corrections/enhancements to me at the above-
  21.  noted addresses.  I do ask that you not distribute this material except as
  22.  originally received, including all source/documentation files in their
  23.  original form.
  24.   If you DO modify or enhance any of this code, please send any such changes
  25.  to me for incorporation into a future version.  Any such enhancements will
  26.  be DONATED, without expectation of compensation or incorporation into
  27.  future versions.  Again, if you distribute this code, please do so in its
  28.  original, unmodified form including all source files and documentation.
  29.  
  30.  Source files included
  31.  =====================
  32.  TDE     .DOC: This documentation.
  33.  TDE     .MAN: How to use TDataEntry in your dialog objects
  34.  TDE     .H  : header file containing class declarations for classes
  35.  TDEFLAGS.H  :   "     "      "       flags and command definitions
  36.  TDE     .CPP: Class TDataEntry
  37.  TDEDATE .CPP: Class TDEDate
  38.  TDEPHONE.CPP: Classes TDEPhone, TDEZipCode, TDEState
  39.  TDENUMS .CPP: Class TDEInteger
  40.  TDECLUST.CPP: Non-TDataEntry classes TDEButton, TDERadioButtons, TDECheckBoxes
  41.  TDEINPLI.CPP: Non-TDataEntry class TDEInputLine
  42.  TDELIB  .PRJ: Project for building library TDELIB.LIB
  43.  TDEDEMO .CPP: Demo program
  44.  TDEDEMO .PRJ: Project for building TDEDEMO.EXE
  45.  
  46. ***************************************************************************/
  47. #define  Uses_TDEButton
  48. #define  Uses_TDERadioButtons
  49. #define  Uses_TDECheckBoxes
  50. #define  Uses_TEvent
  51. #define  Uses_TKeys
  52. #include <tde.h>
  53.  
  54. #ifndef __LIMITS_H          // for UCHAR_MAX
  55. #include <limits.h>
  56. #endif
  57.  
  58. #ifndef __STRING_H
  59. #include <string.h>
  60. #endif
  61.  
  62. //--------------------------------------------------------------------------
  63. //
  64. // **** TDEButton::handleEvent()
  65. //
  66. //  Standard TButton which responds to TDataEntry::globalMode member.
  67. //  ** This object has ofPreProcess set, so MUST check if focused, otherwise
  68. //  **  it will screw things up.
  69. //--------------------------------------------------------------------------
  70. void TDEButton::handleEvent( TEvent& event )
  71. {
  72.   if ( (state & sfFocused) && (event.what == evKeyDown) &&
  73.        ((TDataEntry::globalMode & tdgUpDownEnable) != 0) &&
  74.        (event.keyDown.keyCode == kbUp || event.keyDown.keyCode == kbDown)
  75.      )
  76.   {
  77.     event.keyDown.keyCode =
  78.       (event.keyDown.keyCode == kbUp) ? kbShiftTab : kbTab;
  79.   }
  80.   TButton::handleEvent( event );
  81. }
  82.  
  83. //--------------------------------------------------------------------------
  84. //
  85. // **** TDERadioButtons::TDERadioButtons()
  86. //
  87. //--------------------------------------------------------------------------
  88. TDERadioButtons::TDERadioButtons( const TRect& bounds, TSItem *aStrings,
  89.                                   const char *fName ):
  90.                  TRadioButtons( bounds, aStrings ),
  91.                  fieldName( NULL )
  92. {
  93.   eventMask |= evBroadcast;
  94.   if ( TDataEntry::globalID + 1 > UCHAR_MAX )
  95.     localID = UCHAR_MAX;
  96.   else
  97.     localID = TDataEntry::globalID++;
  98.   if ( fName && (fieldName = new char[strlen(fName) + 1]) != NULL )
  99.     strcpy( fieldName, fName );
  100. }
  101.  
  102. //--------------------------------------------------------------------------
  103. //
  104. // **** TDERadioButtons::~TDERadioButtons()
  105. //
  106. //--------------------------------------------------------------------------
  107. TDERadioButtons::~TDERadioButtons()
  108. {
  109.   delete fieldName;
  110. }
  111.  
  112. //--------------------------------------------------------------------------
  113. //
  114. // **** TDERadioButtons::setData()
  115. //
  116. //--------------------------------------------------------------------------
  117. void TDERadioButtons::setData( void *rec )
  118. {
  119.   TRadioButtons::setData(rec);
  120.   origData = value;
  121. }
  122.  
  123. //--------------------------------------------------------------------------
  124. //
  125. // **** TDERadioButtons::handleEvent()
  126. //
  127. //  Standard TRadioButton which responds to TDataEntry::globalMode member.
  128. //  ** This object has ofPreProcess set, so MUST check if focused, otherwise
  129. //  **  it will screw things up.
  130. //--------------------------------------------------------------------------
  131. void TDERadioButtons::handleEvent( TEvent& event )
  132. {
  133.   if ( event.what == evBroadcast )
  134.   {
  135.     switch ( event.message.command )
  136.     {
  137.       case cmTDQueryChanged:
  138.         if ( origData != sel )
  139.           clearEvent(event);
  140.         return;
  141.       case cmTDGotoNumber:
  142.         if ( localID == *(uchar *)event.message.infoPtr )
  143.           clearEvent(event);
  144.         return;
  145.       case cmTDResetData:
  146.         origData = sel;
  147.         return;
  148.       case cmTDGotoName:
  149.         if ( strcmp( fieldName, (char *)event.message.infoPtr ) == 0 )
  150.           clearEvent(event);
  151.         break;
  152.       default:
  153.         break;
  154.     }
  155.   }
  156.  
  157.   if ( (state & sfFocused) && (event.what == evKeyDown) &&
  158.        (event.keyDown.keyCode == kbEnter) &&
  159.        ((TDataEntry::globalMode & tdgEnterIsTab) != 0)
  160.      )
  161.   {
  162.     event.keyDown.keyCode = kbTab;
  163.   }
  164.   TRadioButtons::handleEvent( event );
  165. }
  166.  
  167. //--------------------------------------------------------------------------
  168. //
  169. // **** TDECheckBoxes::TDECheckBoxes()
  170. //
  171. //--------------------------------------------------------------------------
  172. TDECheckBoxes::TDECheckBoxes( const TRect& bounds, TSItem *aStrings,
  173.                               const char *fName ) :
  174.                TCheckBoxes( bounds, aStrings ),
  175.                fieldName( NULL )
  176. {
  177.   eventMask |= evBroadcast;
  178.   if ( TDataEntry::globalID + 1 > UCHAR_MAX )
  179.     localID = UCHAR_MAX;
  180.   else
  181.     localID = TDataEntry::globalID++;
  182.   if ( fName && (fieldName = new char[strlen(fName) + 1]) != NULL )
  183.     strcpy( fieldName, fName );
  184. }
  185.  
  186. //--------------------------------------------------------------------------
  187. //
  188. // **** TDECheckBoxes::TDECheckBoxes()
  189. //
  190. //--------------------------------------------------------------------------
  191. TDECheckBoxes::~TDECheckBoxes()
  192. {
  193.   delete fieldName;
  194. }
  195.  
  196. //--------------------------------------------------------------------------
  197. //
  198. // **** TDECheckBoxes::setData()
  199. //
  200. //--------------------------------------------------------------------------
  201. void TDECheckBoxes::setData( void *rec )
  202. {
  203.   TCheckBoxes::setData(rec);
  204.   origData = value;
  205. }
  206.  
  207. //--------------------------------------------------------------------------
  208. //
  209. // **** TDECheckBoxes::handleEvent()
  210. //
  211. //  Standard TCheckBox which responds to TDataEntry::globalMode member.
  212. //  ** This object has ofPreProcess set, so MUST check if focused, otherwise
  213. //  **  it will screw things up.
  214. //--------------------------------------------------------------------------
  215. void TDECheckBoxes::handleEvent( TEvent& event )
  216. {
  217.   if ( event.what == evBroadcast )
  218.   {
  219.     switch ( event.message.command )
  220.     {
  221.       case cmTDQueryChanged:
  222.         if ( origData != sel )
  223.           clearEvent(event);
  224.         return;
  225.       case cmTDGotoNumber:
  226.         if ( localID == *(uchar *)event.message.infoPtr )
  227.           clearEvent(event);
  228.         return;
  229.       case cmTDResetData:
  230.         origData = sel;
  231.         return;
  232.       case cmTDGotoName:
  233.         if ( strcmp( fieldName, (char *)event.message.infoPtr ) == 0 )
  234.           clearEvent(event);
  235.         break;
  236.       default:
  237.         break;
  238.     }
  239.   }
  240.  
  241.   if ( (state & sfFocused) && (event.what == evKeyDown) &&
  242.        (event.keyDown.keyCode == kbEnter) &&
  243.        ((TDataEntry::globalMode & tdgEnterIsTab) != 0)
  244.      )
  245.   {
  246.     event.keyDown.keyCode = kbTab;
  247.   }
  248.   TCheckBoxes::handleEvent( event );
  249. }
  250.